package com.example.zqq.shoushipassword.view;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.widget.Toast;

/**
 * toast 工具类
 * @author xingf
 *
 */
public class Toastmsg {
	private static Toast mToast;
	private static Handler mHandler = new Handler();
	private static Runnable r = new Runnable() {
		public void run() {
			mToast.cancel();
		}
	};
	
	// toast
	public static void showToast(Context mContext, String text, int duration) {

		mHandler.removeCallbacks(r);
		if (mToast != null) {
			mToast.setText(text);  // 当前token正在显示，直接修改显示的文本
		    mToast.setDuration(duration);
		} else {
			mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT);
			mToast.setGravity(Gravity.CENTER, 0, 0);
		}
		mHandler.postDelayed(r, duration);

		mToast.show();
	}

	// 默认duration为1000
    public static void Tmsg(Context mContext, String text) {
		Tmsg(mContext, text, 2000);
	}
		
	public static void Tmsg(Context context, String str, int duration) {
		showToast(context, str, duration);
	}

}
